package com.smfx.yxt.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smfx.yxt.daoSqlserver.AttachmentListMapper;
import com.smfx.yxt.daoSqlserver.StudentFruitsMapper;
import com.smfx.yxt.daoSqlserver.TeacherFruitsParamMapper;
import com.smfx.yxt.model.StudentFruits;
import com.smfx.yxt.model.TeacherFruitsParam;
import com.smfx.yxt.page.Page;
import com.smfx.yxt.reqVo.AttachRelationReqVO;
import com.smfx.yxt.reqVo.ScoreSummaryQueryVO;
import com.smfx.yxt.reqVo.StudentFruitsReqVO;
import com.smfx.yxt.service.IStudentFruitsService;
import com.smfx.yxt.utils.StringUtil;
import com.smfx.yxt.view.StudentFruitsView;

@Service("studentFruitsService")
public class StudentFruitsServiceImpl implements IStudentFruitsService {
	
	@Autowired
	private StudentFruitsMapper studentFruitsMapper;
	@Autowired
	private TeacherFruitsParamMapper teacherFruitsParamMapper;
	@Autowired
	private AttachmentListMapper attachmentListMapper;
	
	@Override
	public int insertSelective(StudentFruits record) {
		return studentFruitsMapper.insertSelective(record);
	}

	@Override
	public StudentFruits selectByPrimaryKey(Integer id) {
		return studentFruitsMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(StudentFruits record) {
		return studentFruitsMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public List<StudentFruits> selectListByPage(Page<StudentFruits> page) {
		return studentFruitsMapper.selectListByPage(page);
	}

	@Override
	public List<StudentFruits> selectStudentFruitsList(Integer studentId) {
		return studentFruitsMapper.selectStudentFruitsList(studentId);
	}

	@Override
	public Map<String, Object> getParamMap() {
		List<TeacherFruitsParam> list = teacherFruitsParamMapper.selectList();
		if(!StringUtil.isNullOrEmpty(list)) {
			Map<String, Object> map = new HashMap<>();
			for(TeacherFruitsParam param : list) {
				map.put(param.getParamName(), param.getParamValue());
			}
			return map;
		}
		return null;
	}

	@Override
	public StudentFruitsView selectDetailById(Integer id) {
		return studentFruitsMapper.selectDetailById(id);
	}

	@Override
	public int addStudentFruit(StudentFruitsReqVO reqVO) {
		studentFruitsMapper.insertSelective(reqVO);
		if(reqVO.getAttachIds()!= null) {
			AttachRelationReqVO attachReqVO = new AttachRelationReqVO();
			attachReqVO.setRelationId(Long.valueOf(reqVO.getId()));
			attachReqVO.setAttachIds(reqVO.getAttachIds().split(","));
			attachmentListMapper.updateRelationIdByIds(attachReqVO);
		}
		return 1;
	}

	@Override
	public List<StudentFruits> selectListByParam(ScoreSummaryQueryVO vo) {
		return studentFruitsMapper.selectListByParam(vo);
	}

}
